//
//  OrderDetailsViewController.m
//  Futures
//
//  Created by Cheng on 2017/6/27.
//  Copyright © 2017年 Cheng. All rights reserved.
//

#import "OrderDetailsViewController.h"

@interface OrderDetailsViewController ()

@property (weak, nonatomic) IBOutlet UILabel *exchangeRate;

@property (weak, nonatomic) IBOutlet UIButton *buySellDirection;

@property (weak, nonatomic) IBOutlet UILabel *profit;

@property (weak, nonatomic) IBOutlet UILabel *symbol;

@property (weak, nonatomic) IBOutlet UILabel *Qty;

@property (weak, nonatomic) IBOutlet UILabel *openPrice;

@property (weak, nonatomic) IBOutlet UILabel *closePrice;

@property (weak, nonatomic) IBOutlet UILabel *openDate;

@property (weak, nonatomic) IBOutlet UILabel *closeDate;

@end

@implementation OrderDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"订单详情";
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"back" highlightedIcon:nil target:self action:@selector(back)];
    
    MYLog(@"%@",self.closeOrderModel.properties_aps);
    
    [self updateUI];
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}

- (void)updateUI{
    CloseOrderModel *model = self.closeOrderModel;
    
    if (model.RealizedPL>=0) {
        NSString *str = [NSString stringWithFormat:@"+%d 元",model.RealizedPL];
        self.profit.attributedText = [NSString stringWithaString:str bigFont:21 smallFont:15 color:[UIColor redColor]];
        self.exchangeRate.textColor = [UIColor redColor];
    }else{
        NSString *str = [NSString stringWithFormat:@"%d 元",model.RealizedPL];
        self.profit.attributedText = [NSString stringWithaString:str bigFont:21 smallFont:15 color:[UIColor greenColor]];
        self.exchangeRate.textColor = [UIColor greenColor];
    }
    
    [self.buySellDirection setTitle:model.OpenBuySell forState:UIControlStateNormal];
    
    self.symbol.text = model.Symbol;
    
    self.Qty.text = NSStringFromInt(model.Qty);
    
    self.openPrice.text = NSStringFromFloat(model.OpenPrice);
    
    self.closePrice.text = NSStringFromFloat(model.ClosePrice);
    
    
    self.openDate.text = [model.OpenDate stringByReplacingCharactersInRange:NSMakeRange(10, 1) withString:@" "]; //T换成空格
    
    self.closeDate.text = [model.CloseDate stringByReplacingCharactersInRange:NSMakeRange(10, 1) withString:@" "]; //T换成空格
    // 截取小数点后多余的位数NSCharacterSet stringByTrimmingCharactersInSe +whitespaceCharacterSet 或 +whitespaceAndNewlineCharacterSet 来删除输入字符串的头尾的空白符号
}


@end
